<!DOCTYPE html>
<title>Default passive document level wheel event listener manual test</title>
<link rel="help" href="https://github.com/WICG/interventions/issues/64">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body onload=runTest()>
<div>This is a manual test since there is no way to synthesize wheel events.
Scroll by wheel in the middle of the page to run the test.</div>
</body>
<script>
var cancelable = true;
var wheel_arrived = false;
document.addEventListener("wheel", function (event) {
    cancelable = event.cancelable;
    wheel_arrived = true;
    event.preventDefault();
});

function waitFor(condition) {
  const MAX_FRAME = 200;
  return new Promise((resolve, reject) => {
    function tick(frames) {
      // We requestAnimationFrame either for 200 frames or until condition is
      // met.
      if (frames >= MAX_FRAME)
        reject("Condition did not become true after 200 frames");
      else if (condition())
        resolve();
      else
        requestAnimationFrame(tick.bind(this, frames + 1));
    }
    tick(0);
  });
}

function runTest() {
  promise_test (async () => {
    const pos_x = Math.floor(window.innerWidth / 2);
    const pos_y = Math.floor(window.innerHeight / 2);
    const delta_x = 0;
    const delta_y = 100;
    await new test_driver.Actions()
       .scroll(pos_x, pos_y, delta_x, delta_y).send();
    await waitFor(()=> { return wheel_arrived; });
    assert_false(cancelable);
  }, "Wheel events are non-cancelable since the event listener is treated as passive.");
}
</script>
